package com.py.korona.db.model;

import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import com.py.korona.db.UriBuilder;
import com.py.korona.db.model.base.Entity;
import com.py.korona.db.model.base.EntityDescription;
import com.py.korona.db.model.base.EntityProperty;

public class GeopointEntity extends Entity {
    public static String             Table             = "geopoint";
    public static String             TableFieldNameID  = "_id";
    public static String             TableFieldNameLat = "lat";
    public static String             TableFieldNameLon = "lon";
    private static EntityDescription entityDescription_;

    public static EntityDescription entityDescription() {
        if (null == entityDescription_) {
            entityDescription_ = new EntityDescription();
            entityDescription_.addProperty(new EntityProperty(GeopointEntity.TableFieldNameID, "integer", null, "primary key autoincrement"));
            entityDescription_.addProperty(new EntityProperty(GeopointEntity.TableFieldNameLat, "float", null, ""));
            entityDescription_.addProperty(new EntityProperty(GeopointEntity.TableFieldNameLon, "float", null, ""));
        }
        return entityDescription_;
    }

    public static String entityTableName() {
        return GeopointEntity.Table;
    }

    public static String uriAuthority() {
        return "GeopointContentProvider";
    }

    public static String uriBasePath() {
        return "geopoints";
    }
    private float lat;
    private float lon;

    public float getLat() {
        return lat;
    }

    public float getLon() {
        return lon;
    }

    public void setLat(float lat) {
        this.lat = lat;
    }

    public void setLon(float lon) {
        this.lon = lon;
    }

    @Override
    protected ContentValues contentValues() {
        ContentValues contentValues = new ContentValues();
        contentValues.put(GeopointEntity.TableFieldNameLat, this.getLat());
        contentValues.put(GeopointEntity.TableFieldNameLon, this.getLon());
        return contentValues;
    }

    @Override
    protected Uri objectsListUri() {
        return UriBuilder.objectListUri(GeopointEntity.uriAuthority(), GeopointEntity.uriBasePath());
    }

    @Override
    protected void onDataChanged(Cursor cursor) {
        this._id = cursor.getLong(cursor.getColumnIndexOrThrow(GeopointEntity.TableFieldNameID));
        this.lat = cursor.getFloat(cursor.getColumnIndexOrThrow(GeopointEntity.TableFieldNameLat));
        this.lon = cursor.getFloat(cursor.getColumnIndexOrThrow(GeopointEntity.TableFieldNameLon));
    }
}
